import sys
sys.path.append('../code')

import numpy as np
import pandas as pd

from lp import *
from classification import *

import argparse
import time
import warnings

from pathlib import Path
import pickle

def parse_commandline():
    """Parse the arguments given on the command-line.
    """
    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument("--params", nargs='+', default=None)

    args = parser.parse_args()

    return args

###############################################################################
# BEGIN MAIN FUNCTION
###############################################################################
if __name__ == '__main__':
    warnings.simplefilter('ignore')
    seed = 42
    np.random.seed(seed)
    args = parse_commandline()
    
    lmd = float(args.params[0])
    step_size = 5

    df = pd.read_csv("../data/diabetes.csv")

    Y_columns = [y for y in df.columns if 'admit' in y]
    G_columns = ['black', 'female']

    Y_column = 'readmit_binary'
    G_column = 'female'
    X_columns = df.columns.drop(Y_columns)
    X_columns = X_columns.drop(G_column)
    
    angles_degrees = np.arange(0, 360, step_size)
    angles_radians = np.radians(angles_degrees)
    sin_values = np.sin(angles_radians)
    cos_values = np.cos(angles_radians)

    obj_list = []
    for i in range(cos_values.shape[0]):
        obj_list.append((cos_values[i], sin_values[i]))

    res = CV_frontier(df, Y_column, G_column, X_columns, obj_list,
                      n_splits=5, seed=seed, lmd=lmd, solver=cp.GUROBI,
                      verbose=False, standardize=True)
    
    
    # save the results
    filepath = '/home/kop5674/FA_frontier/result/diabetes/gender/'
    filename = f'res_LP_diabetes_gender_{lmd}_{seed}.pkl'
    
    with open(filepath+filename, 'wb') as pickle_file:
        pickle.dump(res, pickle_file)

